package org.rainbowinverted.charging.device.connect.bl.server.handler;

import com.dix.codec.bkv.BKV;
import io.netty.channel.ChannelHandler;
import io.netty.channel.ChannelHandlerContext;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.rainbowinverted.charging.device.connect.bl.server.message.out.BlDeviceMessageOut;
import org.springframework.stereotype.Component;

import java.time.LocalDateTime;

/**
 * @author huaiping
 */
@Slf4j
@Component
@ChannelHandler.Sharable
@AllArgsConstructor
public class BlDeviceDisconnectHandler extends BlAbstractHandler<Void, BlDeviceMessageOut>{
    @Override
    public void write(BlDeviceMessageOut message, BKV bkv) {
    }

    @Override
    public void read(ChannelHandlerContext ctx, BKV bkv) {
        Long deviceNo = getDeviceNo(ctx);
        LocalDateTime.now();
        removeChannel(ctx);
        log.info("device disconnect: {}", deviceNo);
    }
}
